@import '../../styles/variables.less';
@import '../../styles/themes/@{so-theme}.less';

@menu-prefix: ~'@{so-prefix}-menu';
@transition-duration: .2s;
@expand-width: 40px;

.@{menu-prefix} {
  position: relative;
  z-index: @zindex-navbar;
  height: 100%;
  padding: 0;
  margin: 0;
  //box-shadow: @menu-box-shadow-base;
  background: @menu-bg;
  line-height: 0; // Fix display inline-block gap
  list-style: none;
  outline: none;

  ul {
    padding: 0;
    margin: 0;
    list-style: none;
    // min-width: 100%;
  }

  &-root {
    box-shadow: none;
  }

  ul.@{menu-prefix}-root {
    margin-left: -1px;
  }

  &-item {
    a {
      display: block;
      color: @menu-item-color;
      white-space: nowrap;
      transition: all @transition-duration;

      &:focus {
        text-decoration: none;
      }

      &:hover {
        color: @menu-item-light-hover-color;
        background-color: @menu-item-light-hover-bgc;
      }
    }

    &.@{menu-prefix}-disabled > a {
      color: @menu-disabled-color;
      cursor: not-allowed;
    }
  }

  &-title {
    position: relative;
    height: @menu-item-height;
    padding: 0 20px;
    line-height: @menu-item-height;
    font-size: @menu-item-font-size;
  }

  &-has-children {
    > .@{menu-prefix}-title {
      padding-right: @expand-width;
      .@{menu-prefix}-expand {
        position: absolute;
        cursor: pointer;
        transition: all @transition-duration;
        right: 0;
        top: 0;
        bottom: 0;
        width: @expand-width;
        .caret(down);
        &:after {
          position: absolute;
          top: 50%;
          right: 16px;
          transform: @menu-title-transform;
        }
      }
    }
  }

  &-highlight > &-title {
    color: @menu-highlight-color;
  }

  &-list {
    display: none;

    .@{menu-prefix}-has-children.@{menu-prefix}-open {
      & > .@{menu-prefix}-title .@{menu-prefix}-expand {
        &:after {
          transform: @menu-title-open-transform;
        }
      }

      & > .@{menu-prefix}-list {
        display: block;
      }
    }
  }

  ul&-root {
    display: block;
  }

  &&-inline {
    border-right: solid 1px @menu-border-color;
  }

  &-inline {
    &.@{menu-prefix}-root {
      box-sizing: content-box;
    }

    & > .@{menu-prefix}-item {
      display: block;
      &.@{menu-prefix}-selectable {
        > a .@{menu-prefix}-expand:hover {
          background: @primary-color-fade-10;
        }
      }
    }

    .@{menu-prefix}-active.@{menu-prefix}-no-children,
    .@{menu-prefix}-active.@{menu-prefix}-selectable {
      padding: @menu-active-padding-vertical @menu-active-padding-horizontal;
      > a {
        background: @menu-item-active-bg;
        color: @menu-item-active-color;
        border-radius: @menu-active-border-radius;
        text-indent: @menu-active-padding-horizontal-negative;

        &:before {
          position: absolute;
          top: 0;
          right: 0px;
          width: @menu-active-bar;
          height: 100%;
          background: @menu-active-bar-color;
          content: ' ';
        }
      }
    }

    .@{menu-prefix}-active.@{menu-prefix}-has-children > a {
      color: @menu-highlight-color;
    }
  }

  &-horizontal {
    height: 42px;
    margin-left: 0;

    &.@{menu-prefix}-root {
      border-bottom: solid 1px @menu-border-color;
      display: inline-block;
      white-space: nowrap;
      min-width: 100%;
    }

    .@{menu-prefix}-wrapper {
      position: absolute;
      overflow: hidden;
      width: 100%;
    }

    &.@{menu-prefix}-has-open {
      .@{menu-prefix}-wrapper {
        height: 100vh;
      }
    }

    &:hover .@{menu-prefix}-bar {
      display: block;
    }

    & > .@{menu-prefix}-item {
      position: relative;
      display: inline-block;
    }

    & > .@{menu-prefix}-active > a,
    & > .@{menu-prefix}-highlight > a {
      position: relative;
      color: @menu-item-active-indicator;

      &:before {
        position: absolute;
        right: 0;
        bottom: -1px;
        left: 0;
        height: 2px;
        background: @menu-item-active-indicator;
        content: ' ';
      }
    }

    .@{menu-prefix}-active.@{menu-prefix}-no-children > a {
      &:after {
        width: 0;
      }
    }

    .@{menu-prefix}-root .@{menu-prefix}-list {
      position: absolute;
      top: 100%;
      left: 0;
      min-width: 100%;
      padding: 4px 0;
      margin-top: 4px;
      background: @menu-bg;
      border-radius: 4px;
      box-shadow: @menu-box-shadow-base;
    }
  }

  &-inline, &-horizontal {
    .@{menu-prefix}-in-path.@{menu-prefix}-has-children > a {
      color: @colors-primary;
    }
  }

  ul.@{menu-prefix}-horizontal.@{menu-prefix}-root {
    margin-left: 0;
  }

  &-bar {
    display: none;
  }

  &-vertical {
    &.@{menu-prefix}-root {
      border-right: solid 1px @menu-border-color;
    }

    & > .@{menu-prefix}-item {
      position: relative;
    }

    &:hover .@{menu-prefix}-bar {
      display: block;
    }

    &.@{menu-prefix}-scroll .@{menu-prefix}-wrapper {
      position: absolute;
      overflow: hidden;
      min-width: 100%;
      height: 100%;
      overflow-anchor: none;
    }

    &.@{menu-prefix}-has-open .@{menu-prefix}-wrapper {
      width: 100vw;
    }

    .@{menu-prefix}-root .@{menu-prefix}-list {
      position: absolute;
      top: 0;
      left: 100%;
      width: auto;
      min-width: auto;
      padding: 4px 0;
      margin-left: 3px;
      background: @menu-bg;
      border-radius: 4px;
      box-shadow: @menu-box-shadow-base;
    }

    .@{menu-prefix}-has-children,
    .@{menu-prefix}-has-children.@{menu-prefix}-open {
      & > .@{menu-prefix}-title .@{menu-prefix}-expand {
        &:after {
          transform: @menu-title-vertical-transform;
        }
      }
    }

    .@{menu-prefix}-root .@{menu-prefix}-open-up .@{menu-prefix}-list {
      top: auto;
      bottom: 0;
    }

    .@{menu-prefix}-active.@{menu-prefix}-no-children > a {
      background: @menu-item-active-bg;
      color: @menu-item-active-color;
    }

    .@{menu-prefix}-in-path.@{menu-prefix}-has-children > a {
      background: @menu-item-active-bg;
      color: @menu-item-active-color;

      &::before {
        content: ' ';
        position: absolute;
        right: 0;
        top: 0;
        width: @menu-vertical-in-path-bar-width;
        border-top-left-radius: @menu-vertical-in-path-bar-width;
        border-bottom-left-radius: @menu-vertical-in-path-bar-width;
        height: 100%;
        background-color: @menu-active-bar-color;
      }
    }

    .@{menu-prefix}-in-path.@{menu-prefix}-no-children.@{menu-prefix}-active > a,
    .@{menu-prefix}-in-path.@{menu-prefix}-has-children.@{menu-prefix}-active > a {
      background-color: @menu-item-has-children-active-bgc;
      color: @menu-item-has-children-active-color;
    }
  }

  &-dark {
    &,
    .@{menu-prefix}-list {
      background-color: @menu-dark-bg;
      color: @menu-dark-item;
    }

    .@{menu-prefix}-item {
      a {
        color: @menu-dark-item;

        &:hover {
          color: @menu-item-dark-hover-color;
          background-color: @menu-item-dark-hover-bgc;
        }
      }
    }

    &.@{menu-prefix}-horizontal,&.@{menu-prefix}-vertical {
      border-color: @menu-dark-bg;

      .@{menu-prefix}-list {
        background-color: @menu-dark-bg;
        color: @menu-dark-item;
      }
    }

    &.@{menu-prefix}-inline,
    &.@{menu-prefix}-vertical,
    &.@{menu-prefix}-horizontal {
      .@{menu-prefix}-item.@{menu-prefix}-active.@{menu-prefix}-no-children,
      .@{menu-prefix}-item.@{menu-prefix}-active.@{menu-prefix}-selectable  {
        > a {
          background: @menu-dark-active-bg;
          color: @menu-dark-active-color;

          &:after,
          &after:before {
            width: 0;
            height: 0;
          }
        }
      }

      .@{menu-prefix}-active > a,
      .@{menu-prefix}-highlight > a {
        color: @menu-dark-active-color;
      }
    }

    .@{menu-prefix}-submenu-title:hover {
      color: @menu-bg;

      > a {
        color: @menu-bg;
      }
    }


    &:not(.@{menu-prefix}-horizontal) {
      .@{menu-prefix}-has-children.@{menu-prefix}-in-path > a {
        &:before {
          content: ' ';
          position: absolute;
          left: 0;
          top: 0;
          width: @menu-active-bar;
          height: 100%;
          background-color: @menu-dark-active-bar-color;
        }
      }
    }

    &.@{menu-prefix}-vertical {
      ul.@{menu-prefix}-root {
        margin-left: 0;
        border-right: none;

        & > li.@{menu-prefix}-item > a {
          &:hover {
            background-color: @menu-item-dark-hover-bgc;
          }
        }

        & > .@{menu-prefix}-item:not(.@{menu-prefix}-in-path) > a {
          background-color: @menu-root-node-bgc;
        }
      }

      .@{menu-prefix}-has-children {
        .@{menu-prefix}-title {
          &::after {
            right: 18px;
          }
        }
      }

      .@{menu-prefix}-in-path.@{menu-prefix}-has-children > a {
        background-color: @menu-vertical-dark-parent-active-bgc;
        color: @menu-dark-active-color;

        &::before {
          width: @menu-vertical-in-path-bar-width;
          right: auto;
          left: 0;
          border-top-right-radius: @menu-vertical-in-path-bar-width;
          border-bottom-right-radius: @menu-vertical-in-path-bar-width;
          border-top-left-radius: 0;
          border-bottom-left-radius: 0;
        }
      }

      // vertical menu > has-chilren + in-path + active
      .@{menu-prefix}-in-path.@{menu-prefix}-has-children.@{menu-prefix}-active > a {
        background: @menu-dark-active-bg;
        color: @menu-dark-active-color;
      }

      .@{menu-prefix}-item > a {
        background-color: @menu-root-node-bgc;
      }
    }

    ul.@{menu-prefix}-root {
      &> li.@{menu-prefix}-item {
        & > a {
          background-color: @menu-root-node-bgc;

          &:hover {
            background-color: @menu-item-dark-hover-bgc;
          }
        }
        & > ul {
          border-top: 1px solid @menu-children-segmentation;
        }
      }
    }

    &.@{menu-prefix}{
      .@{menu-prefix}-caret-solid {
        .@{menu-prefix}-title {
          & > .@{menu-prefix}-caret.@{menu-prefix}-has-childs {
              border-top-color: @menu-dark-item;
          }

          &:hover {
            & > .@{menu-prefix}-caret.@{menu-prefix}-has-childs {
              border-top-color: @menu-item-dark-hover-color;
            }
          }
        }
      }
    }

    &.@{menu-prefix}-inline {
      .@{menu-prefix}-selectable {
        > a .@{menu-prefix}-expand:hover {
          background: @primary-color-fade-60;
        }
      }
    }
    &.@{menu-prefix}-inline, &.@{menu-prefix}-horizontal {
      .@{menu-prefix}-in-path.@{menu-prefix}-has-children > a {
        color: @menu-dark-item;
      }
    }
  }

  .@{menu-prefix}-has-children.@{menu-prefix}-caret-solid {

    &.@{menu-prefix}-open {
      & > .@{menu-prefix}-title {
        .@{menu-prefix}-caret {
          transform: rotate(180deg);
          transform-origin: 50% 37.5%;
        }
      }
    }
    & > .@{menu-prefix}-title {
      &:after {
        content: none;
      }
    }

    & > .@{menu-prefix}-title  {
      padding-right:  20px;
    }
  }

  .@{menu-prefix}-caret-solid {
    .@{menu-prefix}-title {
      & > .@{menu-prefix}-caret {
        position: relative;
        width: 0;
        height: 0;
        border: @menu-caret-solid-width solid transparent;
        border-top: @menu-caret-solid-height solid transparent;
        display: inline-block;
        transform: translateY(25%);
        margin-right: 8px;


        &.@{menu-prefix}-has-childs {
          border-top-color: @menu-item-color;
        }
      }

      &:hover {
        & > .@{menu-prefix}-caret.@{menu-prefix}-has-childs {
          border-top-color: @menu-item-light-hover-color;
        }
      }
    }
  }


  &.@{menu-prefix}-rtl {
    direction: rtl;
    text-align: right;

    &:not(.@{menu-prefix}-horizontal) {
      .@{menu-prefix}-active.@{menu-prefix}-no-children {
        a > {
          &:before {
            position: absolute;
            top: 0;
            left: 0px;
            width: 3px;
            height: 100%;
            background: @menu-item-active-indicator;
            content: ' ';
          }

          &:after  {
            content: none;
          }
        }
      }
    }


    .@{menu-prefix}-has-children:not(.@{menu-prefix}-caret-solid) > .@{menu-prefix}-title {

      padding-left: 40px;
      padding-right: 20px;

      &:after {
        right: auto;
        left: 16px;
      }

      &:before {
        left: auto;
        right: 0;
      }
    }

    .@{menu-prefix}-has-children.@{menu-prefix}-open {
      & > .@{menu-prefix}-title {
        &:after {
          transform: @menu-title-open-transform;
        }
      }
    }

    .@{menu-prefix}-has-children.@{menu-prefix}-caret-solid > .@{menu-prefix}-title{
      .@{menu-prefix}-caret {
        margin-right: 0;
        margin-left: 8px;
      }
    }

    &.@{menu-prefix}-vertical {
      .@{menu-prefix}-root  .@{menu-prefix}-list.@{menu-prefix}-vertical {
        left: auto;
        right: 100%;
        margin-left: 0;
        margin-right: 3px;
      }
    }
  }
}
